﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRasta.Configuration;
using uREST.Core.Services;
using uREST.Core.Resources;
using uREST.Blog.Resources;
using uREST.Core;
using uREST.Blog.Handlers;
using uREST.Core.Codecs;
using OpenRasta.Web;

namespace uREST.Blog.Services
{
    public class PostService : IuRESTService
    {
        public EndPoint EndPoint
        {
            get
            {
                return new EndPoint
                {
                    Name = "Post Service",
                    Description = "",
                    Href = typeof(List<Post>).CreateUri("PostList").ToString()
                };
            }
        }

        public void RegisterHandlers()
        {
            ResourceSpace.Has.ResourcesOfType<List<Post>>()
                .AtUri(uRESTConfig.BaseUrl + "/posts").Named("PostList")
                .And.AtUri(uRESTConfig.BaseUrl + "/blogs/{blogId}/posts").Named("PostList")
                .HandledBy<PostHandler>()
                .TranscodedBy<JsonNetCodec>();

            ResourceSpace.Has.ResourcesOfType<Post>()
                .AtUri(uRESTConfig.BaseUrl + "/posts/{id}").Named("Post")
                .And.AtUri(uRESTConfig.BaseUrl + "/posts/{id}?permanent={permanent}").Named("Post")
                .HandledBy<PostHandler>()
                .TranscodedBy<JsonNetCodec>();
        }
    }
}
